<?php
class item_passwordforum extends template_item
{
	var $default_name = "Buy Password for a Forum";
	var $default_description = "Use this item to gain a password to a password locked forum.";
	
	var $allow_multiple = 1;
	
	var $item_config = array();
	
	function load_item(&$item)
	{
		parent::load_item($item);
		
		if($item['item_config'] || $item['item_id'] != 0)
		{
			$this->item_config = unserialize($item['item_config']);
		}
		else
		{
			$this->item_config['forum'] = 0;
		}
	}
	
	function admin_form()
	{
		$this->ipsclass->forums->forums_init();
		
		$forums = array();
		foreach($this->ipsclass->forums->forum_by_id as $f_id => $forum)
		{
			if(!$forum['password'])
			{
				continue;
			}
			$forums[] = array($f_id,$forum['name']." (Forum ID: ".$f_id.")");
		}
		
		$html .= $this->ipsclass->adskin->add_td_row(array(
															"<b>Which forum to provide a password?</b>",
															$this->ipsclass->adskin->form_dropdown("item[".$this->item['item_id']."][forum]", $forums, $this->item_config['forum']),
													)	);
		
		return $html;
	}
	
	function admin_save(&$item_info, $input)
	{
		$save = array();
		$save['forum'] = intval($input['forum']);
		
		$item_info['item_config'] = serialize($save);
	}
	
	function public_use_form($inventory_ids = array())
	{
		$this->delete_items($inventory_ids);
		
		$inv_id = reset($inventory_ids);
		$this->_write_log($inv_id, "Got password for the forum, <a href='{$this->ipsclass->base_url}showforum={$this->item_config['forum']}'>{$this->ipsclass->forums->forum_by_id[$this->item_config['forum']]['name']}</a>");
		
		$this->ipsclass->load_language('lang_market_items');
		
		return <<<EOF
<div class='formsubtitle'>{$this->ipsclass->lang['forum_password']}</div>
<table class='ipbtable' cellspacing='0' cellpadding='0'>
	<tr>
		<td class='row1' align='left'>
			<b><a href='{$this->ipsclass->base_url}showforum={$this->item_config['forum']}'>{$this->ipsclass->forums->forum_by_id[$this->item_config['forum']]['name']}</a></b>
		</td>
		<td class='row2' align='right'>
			{$this->ipsclass->forums->forum_by_id[$this->item_config['forum']]['password']}
		</td>
	</tr>
</table>
EOF;
	}
	
	function input_done()
	{
		return false;
	}
}
?>